package com.clps.algorithm.chapter14.房屋偷盗;

public class 房屋偷盗_03 {

    public static void main(String[] args) {

    }
    public  int rob(int[] nums){
        if(nums.length == 0){
            return  0;
        }

        int[] dp = new int[2];
        dp[0] = nums[0];

        if(nums.length >1){
            dp[1] = Math.max(nums[0],nums[1]);
        }

        for (int i = 0; i <nums.length ; i++) {
            dp[i%2] = Math.max(dp[(i-1) % 2], dp[(i-2) % 2] + nums[i]);
        }

        return  dp[(dp.length-1)%2];
    }


}
